﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace VanTaiTMS
{
    public partial class AddTab : System.Web.UI.Page
    {
        protected string _getData = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        [System.Web.Services.WebMethod]
        public static string Insert(string Empld, string FirstName,string LastName,string Email)
        {
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Employee;User ID=sa;Password=123456");
            {
                SqlCommand cmd = new SqlCommand("Insert into [Employee](Empld,FirstName,LastName,Email) values('" + Empld + "', N'" + FirstName + "',N'" + LastName + "','" + Email + "')", con);
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    return "True";
                }
            }
        }
        [System.Web.Services.WebMethod]
        public static string UpdateTest(string Empld, string FirstName, string LastName, string Email)
        {
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Employee;User ID=sa;Password=123456");
            {

                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "Update [Employee] SET FirstName = @FirstName,LastName = @LastName,Email = @Email where Empld = @Empld";
                cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar).Value = FirstName;
                cmd.Parameters.Add("@LastName", SqlDbType.NVarChar).Value = LastName;
                cmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = Email;
                cmd.Parameters.Add("@Empld", SqlDbType.VarChar).Value = Empld;
                cmd.ExecuteNonQuery();
                return "True";
            }
        }
        [System.Web.Services.WebMethod]
        public static string Delete()
        {
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Employee;User ID=sa;Password=123456");
            {
                SqlCommand cmd = new SqlCommand("Delete From [Employee]", con);
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    return "True";
                }
            }
        }
        [System.Web.Services.WebMethod]
        public static string GetData()
        {
            string data = string.Empty;
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Employee;User ID=sa;Password=123456");
            {
                string sql = "Select * from [Employee]";
                DataTable dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                da.Fill(dt);
                if (dt != null && dt.Rows.Count > 0)
                {
                    data += "<table class='table table-bordered' id='tblMain' style='cursor: pointer;'>";
                    data += "<thead>";
                    data += "<tr id='row1' onclick='SelectVal(this)'>";
                    data += "<th>Số ID</th>";
                    data += "<th>Tên của bạn</th>";
                    data += "<th>Họ của bạn</th>";
                    data += "<th>Email của bạn</th>";
                    data += "</tr>";
                    data += "</thead>";
                    foreach (DataRow dr in dt.Rows)
                    {
                        data += "<tbody>";
                        data += "<tr onclick='SelectVal(this)'>";
                        data += "<td onclick='SelectVal(this)'>";
                        data += dr["Empld"].ToString();
                        data += "</td>";

                        data += "<td>";
                        data += dr["FirstName"].ToString();
                        data += "</td>";

                        data += "<td>";
                        data += dr["LastName"].ToString();
                        data += "</td>";

                        data += "<td>";
                        data += dr["Email"].ToString();
                        data += "</td>";

                        data += "</tr>";
                        data += "</tbody>";
                    }
                    data += "</table>";
                }
            }
            return data;
        }
    }
}